package io1;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * 对象流:处理流/高级流
 * 1)ObjectInputStream和ObjectOutputStream
 * 2)作用:进行对象的序列化和反序列化
 * 3)对象序列化:将一个Java对象转换为一组字节的过程成为对象为对象序列化
 * 对象反序列化:加一组字节还原为Java对象
 */
public class OOSDemo {
    public static void main(String[] args) throws IOException {
        String name="张三";
        int age = 25;
        String gender = "男";
        String[] otherInfo = {"是一名学生","喜欢打篮球"};
        Student stu = new Student(name,age,gender,otherInfo);
        System.out.println(stu);

        //对象输出流在序列化对象时,必须保证序列化对象实现serializable接口;
        FileOutputStream fos = new FileOutputStream("student.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(stu);
        System.out.println("写出完毕");
        oos.close();
    }
}
